package top.lixunda.ecommerce.server.good.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import top.lixunda.commerce.common.core.entity.MessageObject;
import top.lixunda.ecommerce.server.business.BaseController;
import top.lixunda.ecommerce.server.good.api.entity.db.LogGoodPriceDO;
import top.lixunda.ecommerce.server.good.api.entity.vo.LogGoodPriceVO;
import top.lixunda.ecommerce.server.good.api.controller.ILogGoodPriceController;
import top.lixunda.ecommerce.server.good.service.ILogGoodPriceService;

import java.util.List;

/**
 * @author Xumda
 * @version time:2020/1/15 14:29
 */
@Slf4j
@RestController
public class LogGoodPriceController extends BaseController implements ILogGoodPriceController {

    private final ILogGoodPriceService logGoodPriceService;

    @Autowired
    public LogGoodPriceController(ILogGoodPriceService logGoodPriceService) {
        this.logGoodPriceService = logGoodPriceService;
    }

    /**
     * 根据商品id查询商品的价格变化曲线
     *
     * @param id 商品id
     * @return 价格变化记录，默认时间升序排列
     */
    @Override
    public MessageObject<List<LogGoodPriceVO>> queryByGoodId(Integer id) {
        List<LogGoodPriceDO> logGoodPriceDO = logGoodPriceService.queryByGoodId(id);
        List<LogGoodPriceVO> logGoodPriceVO = LogGoodPriceVO.fromLogGoodPriceDO(logGoodPriceDO);
        return getSuccessMessageObject("获取数据成功", logGoodPriceVO);
    }

    /**
     * 根据商品分类id查询商品某个分类的价格变化曲线
     *
     * @param id 商品分类id
     * @return 价格变化记录，默认时间升序排列
     */
    @Override
    public MessageObject<List<LogGoodPriceVO>> queryByGoodTypeId(Integer id) {
        List<LogGoodPriceDO> logGoodPriceDO = logGoodPriceService.queryByGoodTypeId(id);
        List<LogGoodPriceVO> logGoodPriceVO = LogGoodPriceVO.fromLogGoodPriceDO(logGoodPriceDO);
        return getSuccessMessageObject("获取数据成功", logGoodPriceVO);
    }

}
